﻿Imports System.Collections.Generic

Partial Class WebForm_ManageTrainingRegister_SearchVolunteerControl_AddCleanPlan
    Inherits MyUserControl
    Dim wrManager As New WorkRecordManager
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Public Event OK_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        RaiseEvent OK_Click(Me, New EventArgs)

        Try
            Me.GridView_Volunteers.PageIndex = Me.GridView_Volunteers.PageIndex + 1
        Catch ex As Exception

        End Try
        Me.DoQuery()

        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.PageIndexChanged
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView_Volunteers.PageIndexChanging
        Me.GridView_Volunteers.PageIndex = e.NewPageIndex
        BindGV()
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_Volunteers_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_Volunteers.Sorted
        Me.mpSearch.Show()
    End Sub

    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click
        DoQuery()

        Me.mpSearch.Show()
    End Sub

    Sub DoQuery()
        GridView_Volunteers.Visible = True
 
        Me.BindGV()

    End Sub
    Public Sub BindGV()
        Dim dt As New Data.DataTable
     
        dt = wrManager.AddCleanGetVolunteerData(WorkHeaderID, VolunteerQueryControl1.OrganizationID, VolunteerQueryControl1.VOrganizationID, VolunteerQueryControl1.VolunteerId, VolunteerQueryControl1.VolunteerName, VolunteerQueryControl1.VolunteerTEL)

        If GridView_Volunteers.SortSQL <> "" Then
            dt.DefaultView.Sort = GridView_Volunteers.SortSQL
            dt = dt.DefaultView.ToTable()
        End If
        GridView_Volunteers.DataSource = dt
        GridView_Volunteers.DataBind()
    End Sub

    Protected Sub GridView_Volunteers_Sorting(sender As Object, e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView_Volunteers.Sorting
        Me.BindGV()
        Me.mpSearch.Show()
    End Sub
End Class

Partial Class WebForm_ManageTrainingRegister_SearchVolunteerControl_AddCleanPlan

    Public Sub InitDataAndShow()
        VolunteerQueryControl1.IsVolunteerLeader = IIf(Me.CanAdmin = False And Me.CanQuery = True, True, False)

        VolunteerQueryControl1.InitData()


        'GridView_Volunteers.PageIndex = 0

        ' DoQuery()
        GridView_Volunteers.Visible = False
        VolunteerQueryControl1.mpSearchUniqueID = mpSearch.UniqueID

        Me.mpSearch.Show()

    End Sub

    Public ReadOnly Property SelectedValues() As List(Of String)
        Get
            Dim Volunteers As New List(Of String)

            For Each row As GridViewRow In Me.GridView_Volunteers.Rows
                Dim key As DataKey = Me.GridView_Volunteers.DataKeys(row.RowIndex)

                If TryCast(row.FindControl("CheckBox1"), CheckBox).Checked = True Then
                    Volunteers.Add(key("VolunteerID"))
                End If
            Next

            Return Volunteers
        End Get
    End Property

    Public Property WorkHeaderID() As Integer
        Get
            Return ViewState("WorkHeaderID")
        End Get
        Set(ByVal value As Integer)
            ViewState("WorkHeaderID") = value
        End Set
    End Property




End Class
